package com.cheer.tool;

import cn.hutool.core.lang.Console;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.cheer.entity.QuestionImport;

import java.util.List;

public class QuestionImportTool {


    public static void main(String[] args) {

        // excel 数据
        ExcelReader reader = ExcelUtil.getReader("F:\\大学习\\20221021（二十大）\\二十大题库.xlsx");
        reader.setHeaderAlias(QuestionImport.map);
        List<QuestionImport> questionImports = reader.read(0, 1, QuestionImport.class);

        for (int i = 0; i < questionImports.size(); i++) {

            QuestionImport questionImport = questionImports.get(i);
            String quuestion = questionImport.getQuestion();
            String option = questionImport.getOption();
            String answer = questionImport.getAnswer();
            Integer type = 1;
            if( answer.trim().length() > 1 ){
                type = 2;
            }

            String insertStr = "INSERT INTO `xdxx`.`ex_match_question` (\n" +
                    "\t`type`,\n" +
                    "\t`content`,\n" +
                    "\t`option`,\n" +
                    "\t`answer`,\n" +
                    "\t`is_deleted`,\n" +
                    "\t`create_time`,\n" +
                    "\t`update_time`\n" +
                    ")\n" +
                    "VALUES\n" +
                    "\t(\n" +
                    "\t\t'"+ type +"',\n" +
                    "\t\t'"+ quuestion +"',\n" +
                    "\t\t'"+ option +"',\n" +
                    "\t\t'"+ answer +"',\n" +
                    "\t\t'0',\n" +
                    "\t\t'2022-10-21 13:25:36',\n" +
                    "\t\t'2022-10-21 13:25:36'\n" +
                    "\t);";

            Console.log(insertStr);
        }

    }


}
